using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using System.Linq.Expressions;
using ACME.Northwind.Service.Interfaces;

namespace ACME.Northwind.WCFProxy
{
	/// <summary>
	/// The service implementation for Region object
	/// </summary>
	public partial class RegionService : IRegionService
	{
		#region IRegionService Members

		/// <summary>
		/// Run a selection by the primary key
		/// </summary>
		public RegionDTO SelectByPrimaryKey(int regionid)
		{
			return DataService.Instance.GetRegion(regionid);
		}

		/// <summary>
		/// Run the persist for a list
		/// </summary>
		public bool Persist(List<RegionDTO> list)
		{
			bool retval = true;
			foreach (RegionDTO region in list)
			{
				retval &= this.Persist(region);
			}
			return retval;
		}

		/// <summary>
		/// Run the persist for an object
		/// </summary>
		public bool Persist(RegionDTO dto)
		{
			return (DataService.Instance.PersistRegion(dto) != null);
		}

		/// <summary>
		/// Run a selection using LINQ
		/// </summary>
		public List<RegionDTO> RunSelect(string linq)
		{
			List<RegionDTO> retVal = new List<RegionDTO>();
			retVal.AddRange(DataService.Instance.GetRegionListByLINQ(linq));
			return retVal;
		}

		/// <summary>
		/// Run a paginated selection using LINQ
		/// </summary>
		public PagedQueryResults<RegionDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			return DataService.Instance.GetRegionListPaged(pageIndex, pageSize, ascending, sortColumn, linq);
		}

		/// <summary>
		/// Run a selection for all objects
		/// </summary>
		public List<RegionDTO> RunSelect()
		{
			List<RegionDTO> retVal = new List<RegionDTO>();
			DataServiceClient ds = DataService.Instance;
			retVal.AddRange(ds.GetRegionList());
			return retVal;
		}

		/// <summary>
		/// Return a list of related Territory objects
		/// </summary>
		public List<TerritoryDTO> GetTerritoryList(RegionDTO item)
		{
			List<TerritoryDTO> retval = new List<TerritoryDTO>();
			DataServiceClient ds = DataService.Instance;
			string s = "";
			s += "x.RegionId = " + item.RegionId + "";
			retval.AddRange(ds.GetTerritoryListByLINQ("x => " + s));
			return retval;
		}

		/// <summary>
		/// Delete the specified item
		/// </summary>
		public bool Delete(RegionDTO item)
		{
			DataServiceClient ds = DataService.Instance;
			return ds.DeleteRegion(item);
		}

		#endregion
	}
}
